//
//  JXAddressDynamicViewController.m
//  JXAddressApp
//
//  Created by huawei.zheng on 2018/12/3.
//  Copyright © 2018 zhhw_home. All rights reserved.
//

#import "JXBusinessTabViewController.h"
#import "JXCategoryTitleView.h"
#import <QMUIKit/QMUICommonDefines.h>
#import "JXBaseWebView.h"
#import "JXGovementViewController.h"
#import "JXRegionViewController.h"

@interface JXBusinessTabViewController ()
<
JXCategoryViewDelegate,
UIScrollViewDelegate
>

@property (nonatomic, strong) NSArray      *titles;

@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) UIScrollView      *scrollView;

@end

@implementation JXBusinessTabViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    _titles = @[@"民政职能", @"行政区划"];
    
    
    CGFloat height = SCREEN_HEIGHT - (IS_NOTCHED_SCREEN?88:64) - (IS_NOTCHED_SCREEN?82:48);
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, (IS_NOTCHED_SCREEN?88:64), SCREEN_WIDTH, height)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH*2, height);
    self.scrollView.bounces = NO;
    [self.view addSubview:self.scrollView];
    
    JXGovementViewController *vc1 = [JXGovementViewController new];
    [self addChildViewController:vc1];
    vc1.view.frame = self.scrollView.bounds;
    [self.scrollView addSubview:vc1.view];
    
    JXRegionViewController *vc2 = [[JXRegionViewController alloc] init];
    [self addChildViewController:vc2];
    vc2.view.frame = CGRectMake(self.scrollView.bounds.size.width, 0, self.scrollView.bounds.size.width, self.scrollView.bounds.size.height);
    [self.scrollView addSubview:vc2.view];
    
    self.categoryView.frame = CGRectMake(0, IS_NOTCHED_SCREEN?44:20, SCREEN_WIDTH, 44);
    self.categoryView.delegate = self;
    self.categoryView.contentScrollView = self.scrollView;
    self.categoryView.titles = _titles;
    [self.view addSubview:self.categoryView];
    
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (JXCategoryTitleView *)categoryView {
    if (_categoryView == nil) {
        _categoryView = [[ JXCategoryTitleView alloc] init];
        _categoryView.backgroundColor = [UIColor whiteColor];
    }
    return _categoryView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
